package com.cqq.print.business.controller.statistics;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.druid.util.StringUtils;
import com.cqq.common.core.bean.PageInfoBean;
import com.cqq.print.business.service.StatisticsPublisherService;
import com.cqq.print.business.service.bean.StatisticsPublisherBean;
import com.cqq.print.business.service.bean.StatisticsPublisherQueryBean;
import com.cqq.print.constant.Constant;
import com.cqq.pro.util.DateUtil;

/**
 *	@author CHENQQ
 *	@Date 2016年5月10日
 */

@Controller("statistics")
@RequestMapping(value = { "statistics" }, method = {
		RequestMethod.POST,
		RequestMethod.GET })
public class StatisticsController {

	@Autowired
	private StatisticsPublisherService statisticsPublisherService;
	
	
	@RequestMapping(value = { "publisher" }, method = {
			RequestMethod.GET,
			RequestMethod.POST })
	public String toListAjax(StatisticsPublisherQueryBean queryBean, ModelMap out) throws UnsupportedEncodingException, ParseException{

		String startDate = queryBean.getStartDate();
		String endDate = queryBean.getEndDate();
		if(startDate==null||StringUtils.isEmpty(startDate))
		    startDate = DateUtil.formatDate(DateUtil.getFirstDateOfCurrentMonth());
		if(endDate==null||StringUtils.isEmpty(endDate))
			endDate = DateUtil.getCurrDateAfterAddDays(1);
		else
			endDate = DateUtil.addDaysForDate(endDate,1);
		
		queryBean.setStartDate(startDate+" 00:00:00");
		queryBean.setEndDate(endDate+" 00:00:00");
		queryBean.setStatus(Constant.PUBLISHER_STATUS_UNSTOP);
		PageInfoBean<StatisticsPublisherBean> page = statisticsPublisherService.queryStatisticsPublisher(queryBean);
		out.put("page", page);
		out.put("startDate",startDate);
		out.put("endDate", endDate);
		return "statistics/publisher";
		
	}
}
